<template>
    <main>
        <p style="text-align:center;">请注意! 您正在注销您的管理员账号!</p>
        <el-input v-model="password" show-password type="password" label="当前密码"  placeholder="请输入当前密码"></el-input>
        <br><br>
        <el-input v-model="yes" label="确认框"  placeholder="请输入YES"></el-input>
        <br><br>
        <div style="text-align:center">
        <el-button @click="submit" type="primary" style="width:100%">提交</el-button>
        </div>
    </main>
</template>

<script>
    import {logoutUser} from "../../network/admin";
    export default {
        name: "LogoutUser",
        data(){
            return{
                password:'',
                yes:''
            }

        },
        methods: {
          submit() {
            if (this.yes != 'yes') {
              this.$message.error("请输入密码和YES");
            } else {
              if (localStorage.getItem("admin_adminName") == "admin") {
                this.$message.error("admin账号不允许注销");
              } else {
                this.$confirm('此操作将注销账号, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  logoutUser(this.password).then(response => {
                    this.$message.success(response.data.data);
                    this.$store.dispatch("user/logout");
                  }).catch(()=>{
                  });
                }).catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消操作'
                  });
                });
              }
            }
          }
        }
    }
</script>

<style scoped>
    main{
        margin:100px auto 0;
        width: 33%;
        height:300px;
        line-height: 30px;
        text-align: left;
    }
    p{
        line-height: 30px;
        color: #ff6644;
        font-size: 26px;
        font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
    }
</style>